from django.db import models
from django.utils.html import format_html

# Create your models here.

"""
租房信息表
区域（省市区）	位置（具体到街道）	品牌	是否合租	押金	有无电梯	合租人数	厨房	卫生间	租金（RMB）	面积（cm^2）	是否允许养宠物	水费（顿/元）	电费（度/元）	周边环境	推荐指数	评价
广东省-深圳市-龙岗区	坂田街道	自如	是		有	4	1	1	1800	10	是	4	0.5			

区域信息：内置数据库
品牌：自如，链家，乐有家，公寓，自建房
是否合租：1 是，0否
有无电梯：1有，0无
合租人数：2-10
厨房：1-5
卫生间：1-5
是否允许养宠物：1是，0否

"""
brand_choices = (
    ('ziru', '自如'),
    ('lianjia', '链家'),
    ('leyoujia', '乐有家'),
    ('gongyu', '公寓'),
    ('zizu', '自建房'),)
is_shared_choices = (
    ('1', '是'),
    ('0', '否'),)
has_elevator_choices = (
    ('1', '有'),
    ('0', '无'),)

is_allow_pet_choices = (
    ('1', '是'),
    ('0', '否'),)


class CommonFields(models.Model):
    create_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_at = models.DateTimeField(auto_now=True, verbose_name="更新时间")


class Index(models.IntegerChoices):
    ONE = 1, '强烈不推荐'
    TWO = 2, '不推荐'
    THREE = 3, '一般'
    FOUR = 4, '推荐'
    FIVE = 5, '强烈推荐'
class RentInfo(CommonFields):
    region = models.CharField(max_length=20, verbose_name="区域")
    # location = models.CharField(max_length=100, verbose_name="位置")
    location = models.ForeignKey(to='map.Search', on_delete=models.CASCADE, verbose_name='位置')
    brand = models.ForeignKey(to='basic_info.Brands', on_delete=models.CASCADE, verbose_name='品牌')
    is_sharing = models.CharField(max_length=20, choices=is_shared_choices, verbose_name="是否合租", default='0')
    deposit = models.DecimalField(verbose_name="押金",max_digits=10, decimal_places=2)
    has_elevator = models.CharField(max_length=20, choices=has_elevator_choices, verbose_name="有无电梯", default='0')
    sharing_num = models.CharField(max_length=20, verbose_name="合租人数")
    kitchen = models.CharField(max_length=20, verbose_name="厨房")
    bathroom = models.CharField(max_length=20, verbose_name="卫生间")
    rent = models.DecimalField(verbose_name="租金",max_digits=10, decimal_places=2)
    area = models.DecimalField(verbose_name="面积",max_digits=10, decimal_places=2)
    allow_pet = models.CharField(max_length=20, choices=is_allow_pet_choices, verbose_name="是否养宠物", default='0')
    water_fee = models.DecimalField(verbose_name="水费",max_digits=10, decimal_places=2)
    electric_fee = models.DecimalField(verbose_name="电费",max_digits=10, decimal_places=2)
    surroundings = models.TextField(verbose_name="周边设施")
    recommend_index = models.IntegerField(choices=Index.choices,verbose_name="推荐指数")
    comment = models.TextField(verbose_name="评论")

    def __str__(self):
        return self.region

    class Meta:
        db_table = 'info_rentinfo'
        verbose_name = '房屋信息'
        verbose_name_plural = verbose_name


gender_choices = (
    ('0', '男'),
    ('1', '女'),
)
education_choices = (
    ('0', '本科'),
    ('1', '硕士'),
    ('2', '博士'),
    ('3', '大专'),
    ('4', '高中'),
    ('5', '初中'),
    ('6', '小学'),
)
marriage_choices = (
    ('0', '未婚'),
    ('1', '已婚'),
    ('2', '离异'),
    ('3', '丧偶'),
)


class Tenant(CommonFields):
    name = models.CharField(max_length=20, verbose_name='姓名')
    phone = models.CharField(max_length=20, verbose_name='手机号')
    id_card = models.CharField(max_length=20, verbose_name='身份证号')
    gender = models.CharField(max_length=20, choices=gender_choices, verbose_name='性别')
    age = models.IntegerField(verbose_name='年龄')
    education = models.CharField(max_length=20, choices=education_choices, verbose_name='学历')
    marriage = models.CharField(max_length=20, choices=marriage_choices, verbose_name='婚姻状况')
    hometown = models.CharField(max_length=20, verbose_name='家乡')
    # current_address = models.CharField(max_length=100, verbose_name='现居住址')
    current_address = models.ForeignKey(to='map.Search', on_delete=models.CASCADE, verbose_name='现居住址')
    work_address = models.CharField(max_length=100, verbose_name='工作地点')
    company = models.CharField(max_length=50, verbose_name='任职公司')

    class Meta:
        verbose_name = '租客信息'
        verbose_name_plural = verbose_name

    def __repr__(self):
        return self.current_address
